import {createStore} from "vuex";
import axios from "axios";
//侧边栏关闭与打开状态的通信
export default createStore({
    state:{
        isCollapsed:false,
        activeIndex:'',
        staffInfo: {},
        rootMenuItem: {}
    },
    actions:{
        addMenuItemList:function (context){
            const staffInfo = JSON.parse(localStorage.getItem("staffInfo"))
            if (staffInfo){
                axios.post('http://localhost:8888/rights/get_by_staff_id',{staffId:staffInfo.staffId}).then(resp=>{
                    context.commit('ADD_MENU_ITEM_LIST',resp.data.data|| {})
                }).catch(error=>{
                    console.log(error.message)
                })
            }else {
                console.log("addMenuItemList==>用户没有登录")
            }
        },
        addStaffInfo:function (context,staffInfo){
            context.commit('ADD_STAFF_INFO',staffInfo)
        },
        removeMenuItemList:function (context){
            context.commit('REMOVE_MENU_ITEM_LIST')
        },
        removeStaffInfo:function (context){
            context.commit('REMOVE_STAFF_INFO')
        }
    },
    mutations:{
        closeOrOpenBar(state){
            state.isCollapsed = !state.isCollapsed
        },
        clickActiveIndex(state,activeIndex){
            state.activeIndex = activeIndex
        },
        ADD_MENU_ITEM_LIST(state,rootMenuItem){
            state.rootMenuItem = rootMenuItem
        },
        ADD_STAFF_INFO(state,staffInfo){
            state.staffInfo = staffInfo
        },
        REMOVE_MENU_ITEM_LIST(state){
            state.menuItemList = []
        },
        REMOVE_STAFF_INFO(state){
            state.staffInfo = {}
        }
    }
})